# Makefile

# Compiler
CC = gcc

# Compiler flags
CFLAGS = -Wall -I./include -I./unity

# Directory paths
SRCDIR = src
TESTDIR = test
UNITYDIR = unity

UNITY_SRC = $(UNITYDIR)/unity.c
UNITY_OBJ = $(UNITY_SRC:.c=.o)

# Source files and object files
SRC = $(wildcard $(SRCDIR)/*.c)
OBJ = $(SRC:.c=.o)

# Unit test source files and object files
TEST_SRC = $(filter-out $(SRCDIR)/main.c, $(SRC)) $(wildcard $(TESTDIR)/*.c)
TEST_OBJ = $(TEST_SRC:.c=.o)
TEST_EXEC = tests

# Final executable name
EXEC = myprogram

# Build the main program
all: $(EXEC)

$(EXEC): $(OBJ)
	$(CC) $(LDFLAGS) -o $@ $^

# Compile source files
%.o: %.c
	$(CC) $(CFLAGS) -c $< -o $@

# Build and run unit tests
.PHONY: test
# test: $(OBJ) $(UNITY_OBJ)
#     $(CC) $(CFLAGS) -o $(TEST_EXEC) $(TEST_SRC) $(OBJ) $(UNITY_OBJ)
#     ./$(TEST_EXEC)

test: $(TEST_OBJ) $(UNITY_OBJ)
	$(CC) $(CFLAGS) -o $(TEST_EXEC) $(TEST_SRC) $(UNITY_OBJ)
	./$(TEST_EXEC)

# Clean up generated files
.PHONY: clean
clean:
	rm -f $(OBJ) $(EXEC) $(TEST_OBJ) $(TEST_EXEC)
